/*
package org.example.util;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.printing.PDFPageable;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import java.awt.print.PrinterJob;
import java.io.File;

public class PdfUtil {


    public static void main(String[] args) {
        String pdfPath = "C:\\Users\\15711\\Desktop\\测试打印12 - 副本.pdf";
        String printerName = "HPRT N31C"; // 替换为实际打印机名称

        try (PDDocument document = PDDocument.load(new File(pdfPath))) {
            // 查找打印机
            PrintService printer = findPrinter(printerName);
            if (printer == null) {
                System.out.println("未找到打印机: " + printerName);
                return;
            }

            // 创建打印作业
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintService(printer);
            job.setPageable(new PDFPageable(document));

            // 设置打印属性
            // job.setCopies(2); // 设置份数
            // job.setJobName("订单打印"); // 设置作业名称

            // 执行打印
            job.print();
            System.out.println("PDF 打印任务已提交");

        } catch (Exception e) {
            System.err.println("打印失败: ");
            e.printStackTrace();
        }
    }

    private static PrintService findPrinter(String name) {
        for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
            if (service.getName().equalsIgnoreCase(name)) {
                return service;
            }
        }
        return null;
    }
}
*/
